﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WgFrame.Net
{
    public interface IConnectionCallbacks
    {
        void OnConnected();
        void OnDisconnected();
        void OpResponseReceived(OperationResponse response);
    }

    public class ConnectionCallbacksContainer : List<IConnectionCallbacks>, IConnectionCallbacks
    {
        private readonly WgClient client;

        public ConnectionCallbacksContainer(WgClient client)
        {
            this.client = client;
        }

        public void OnConnected()
        {
            client.UpdateCallbackTargets();

            foreach (IConnectionCallbacks target in this)
            {
                target.OnConnected();
            }
        }

        public void OnDisconnected()
        {
            client.UpdateCallbackTargets();

            foreach (IConnectionCallbacks target in this)
            {
                target.OnDisconnected();
            }
        }

        public void OpResponseReceived(OperationResponse response)
        {
            client.UpdateCallbackTargets();

            foreach (IConnectionCallbacks target in this)
            {
                target.OpResponseReceived(response);
            }
        }
    }
}
